package com.yh.hljapp.modules.adatper;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yh.hljapp.R;
import com.yh.hljapp.modules.bean.CustPhoneHGZ;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * =========================
 * 版权所有，违法必究
 * 作者：john
 * <p>
 * 工程：FoodBarcode
 * <p>
 * 文件名：CustPhoneAdapter
 * <p>
 * 创建时间：2017.05.23.9:36
 * *****************************
 */
public class CustPhoneHGZAdapter extends ListBaseAdapter<CustPhoneHGZ> {

    private String mType;

    public CustPhoneHGZAdapter(String type) {
        this.mType = type;
    }

    @Override
    protected View getRealView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh = null;
        if (convertView == null || convertView.getTag() == null) {
            convertView = getLayoutInflater(parent.getContext()).inflate(
                    R.layout.item_cust_phone, null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        CustPhoneHGZ custPhone = mDatas.get(position);


        if ("cpdm".equals(mType)) {
            vh.tvPhone.setText("产品代码: " + custPhone.getNumber() + "\n产品名称: " + custPhone.getName() + "\n规格型号: " + custPhone.getModel());
        } else if ("jbzl".equals(mType)) {
            vh.tvPhone.setText("胶棒重量: " + custPhone.getName() + " (Kg)");
        } else if ("hgz".equals(mType)) {
            vh.tvPhone.setText("产品名称: " + custPhone.getName() + "\n单据编号: " + custPhone.getNumber() + "\n生产日期: " + custPhone.getModel());
        } else {
            vh.tvPhone.setText(custPhone.getName());
        }

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.tv_desc)
        TextView tvDesc;
        @InjectView(R.id.tv_phone)
        TextView tvPhone;
        @InjectView(R.id.ll_desc)
        LinearLayout llDesc;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
